<?php
// 获取我的留言信息
// header("content-type:text/html;charset=utf-8");

include_once("conn.php");
include_once("u_getLoginInfo.php");

$select_msg = "SELECT * FROM msg_infos WHERE user_ID = '" . $userID . "' ORDER BY msg_date DESC";
if ($result_msg = mysqli_query($connect_DB, $select_msg)) {
    $count_msg = mysqli_num_rows($result_msg);
    echo "
    <div class='count-info'>共查询到 <b>" . $count_msg . "</b> 条记录：</div>
    <div class='msg-lists-div'>
    ";
    if ($count_msg <= 0) {
        echo "
        <div class='list-div'>
            <div class='none-list'>暂无您的留言信息</div>
        </div>
        ";
    } else {
        while ($row_msg = mysqli_fetch_object($result_msg)) {
            $select_replay = "SELECT * FROM replay_msg_infos WHERE msg_ID = '" . $row_msg->msg_ID . "' ORDER BY replay_date DESC";
            if ($result_replay = mysqli_query($connect_DB, $select_replay)) {
                echo "
                <div class='list-div'>
                    <div class='msg-content'>" . $row_msg->msg_content . "</div>
                    <div class='msg-info'>您发布于 " . $row_msg->msg_date . " | <a href='u_delMsg.php?msgID=". $row_msg->msg_ID."'>点此删除</a></div>
                ";
                if (mysqli_num_rows($result_replay) <= 0) {
                    echo "
                    <div class='replay-div'>
                        <div class='replay-none'>暂无回复信息</div>
                    </div>
                    ";
                } else {
                    while ($row_replay = mysqli_fetch_object($result_replay)) {
                        $select_doc = "SELECT * FROM doc_infos WHERE doc_ID = '" . $row_replay->doc_ID . "'";
                        $result_doc = mysqli_query($connect_DB, $select_doc);
                        $row_doc = mysqli_fetch_object($result_doc);
                        echo "
                        <div class='replay-div'>
                            <div class='replayer'><b>" . $row_doc->doc_Name . "</b> 医生回复：</div>
                            <div class='replay-content'>" . $row_replay->replay_content . "</div>
                            <div class='replay-date'>" . $row_replay->replay_date . "</div>
                        </div>
                        ";
                    }
                }
                echo "</div>";
            }
        }
    }
    echo "</div>";
}

$connect_DB->close();
?>